package com.company.behavioral.visitor_pattern.object_structure;

import com.company.behavioral.visitor_pattern.element.Employee;
import com.company.behavioral.visitor_pattern.visitor.Department;

import java.util.ArrayList;

/**
 * 员工列表
 * @ClassName EmployeeList
 * @Author tiezheng.han
 * @Date 2020/9/7 16:45
 **/
public class EmployeeList {

    /**
     * 定义一个集合用于存储员工对象
     */
    private ArrayList<Employee> list = new ArrayList<>();

    public void addEmployee(Employee employee){
        list.add(employee);
    }

    /**
     * 遍历访问员工集合中的每一个员工对象
     * @param handler
     */
    public void accept(Department handler){
        for (Object obj : list) {
            ((Employee)obj).accept(handler);
        }
    }
}
